@extends('admin.main')
@section('content')
    <div class="daohang">
        <ul>
            <li>
                <button type="button" class="am-btn am-btn-default am-radius am-btn-xs">医师坐诊管理>
                </button>
            </li>
            <li>
                <button type="button" class="am-btn am-btn-default am-radius am-btn-xs">添加医师坐诊计划
                </button>
            </li>
        </ul>
    </div>
    <div class="admin-biaogelist">

        <div class="listbiaoti am-cf">
            <ul class="am-icon-flag on">添加医师坐诊计划</ul>
        </div>

        <div class="fbneirong">
            <form class="am-form" action="{{urlAdmin('doctor','postAddWorkTime')}}" method="post" onsubmit="return checkForm()">
                <input type="hidden" name="id" value="" />
                <div class="am-form-group am-cf">
                    <div class="zuo">选择坐诊日期：</div>
                    <div class="you">
                        <div class="radiobox" id="sel-day">
                            @foreach($daylist as $v)
                            <div class="check">
                                <input type="checkbox" value="{{$v}}"  name="daylist[]">
                                {{$v}}
                            </div>
                           @endforeach
                        </div>
                    </div>
                </div>
                <input type="hidden" value="{{$_GET['id']}}" name="d_id">
                <div class="am-form-group am-cf">
                    <div class="zuo">选择坐诊类型：</div>
                    <div class="you">
                         <div class="radiobox" id="sel_menu">
                              <div class="radio active">
                                  <input type="radio" value="1" checked name="appiont_type">
                                  门诊
                              </div>
                              <div class="radio">
                                 <input type="radio" value="2" name="appiont_type">
                                  电话
                              </div>
                         </div>
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="zuo">选择坐诊时间段：</div>
                    <div class="you">
                        <div class="radiobox" id="sel-menu1">
                            <div class="radio active">
                                <input type="radio" value="1" checked name="work_type">
                                全天
                            </div>
                            <div class="radio">
                                <input type="radio" value="2" name="work_type">
                                上午
                            </div>
                            <div class="radio">
                                <input type="radio" value="3" name="work_type">
                                下午
                            </div>
                        </div>
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="zuo">安排坐诊时间：</div>
                    <div class="you">
                        <div class="radiobox" id="sel-time">
                            @if(!empty($res))
                            @foreach($res as $v)
                            <div class="check active">
                                <input type="checkbox" checked value="{{$v}}" name="time_area[]">
                                {{$v}}
                            </div>
                            @endforeach
                            @endif
                        </div>
                    </div>
                </div>
                <div class="am-form-group am-cf">
                    <div class="you" style="margin-left: 11%;">
                        <input type="submit"  class="am-btn am-btn-success am-radius" value="添加">
                    </div>
                </div>
            </form>
        </div>

    @include('admin.footer')
    @section('script')
        <script>
            var message = "{{Session::get('message')}}";
            $(window).ready(function () {
                if (message) {
                    layer.msg(message, {
                        time: 3000 //2秒关闭（如果不配置，默认是3秒）
                    });
                }
            });
            var sel_menu = document.getElementById('sel_menu');
            var se_Elm = sel_menu.getElementsByTagName('div');
            var input = sel_menu.getElementsByTagName('input')
            for(var i=0;i<se_Elm.length;i++){
                  se_Elm[i].index = i;
                  se_Elm[i].onclick = function(){
                         for (var j=0;j<se_Elm.length;j++){
                               se_Elm[j].className = 'radio';
                               input[j].checked = false;
                         }
                         this.className = 'radio active'
                         input[this.index].checked = true;
                  }
            }

            var sel_menu1 = document.getElementById('sel-menu1');
            var se_Elm1 = sel_menu1.getElementsByTagName('div');
            var input1 = sel_menu1.getElementsByTagName('input')
            for(var i=0;i<se_Elm1.length;i++){
                se_Elm1[i].index = i;
                se_Elm1[i].onclick = function(){
                    for (var j=0;j<se_Elm1.length;j++){
                        se_Elm1[j].className = 'radio';
                        input1[j].checked = false;
                    }
                    this.className = 'radio active'
                    input1[this.index].checked = true;
                    var type = input1[this.index].value-1;
                    getTimeArea(type);
                }
            }

            function getTimeArea(type){
                $.ajax({
                    type:"get",
                    url:"{{urlAdmin('doctor','getTimeArea')}}?type="+type,
                    dataType:"json",
                    success:function (res){
                         if (res){
                               var time_html = '';
                               for (var i=0;i<getJsonLength(res);i++){
                                    time_html+='<div class="check active" onclick="sel()"><input type="checkbox" checked value="'+res[i]+'" name="time_area[]" >'+res[i]+'</div>';
                                   document.getElementById('sel-time').innerHTML = time_html;
                               }
                         }
                    }
                })
            }

            function getJsonLength(jsonData){

                var jsonLength = 0;

                for(var item in jsonData){

                    jsonLength++;

                }

                return jsonLength;

            }

            sel2();
            function sel2() {
                var sel_menu3 = document.getElementById('sel-day');
                var se_Elm3 = sel_menu3.getElementsByTagName('div');
                var input3 = sel_menu3.getElementsByTagName('input');
                for (var i = 0; i < se_Elm3.length; i++) {
                    se_Elm3[i].index = i;
                    se_Elm3[i].onclick = function () {
                        if (this.className == "check active") {
                            this.className = 'check';
                            input3[this.index].checked = false;
                        } else {
                            this.className = 'check active';
                            input3[this.index].checked = 'true';
                        }
                    }
                }
            }

            sel();
            function sel() {
                var sel_menu2 = document.getElementById('sel-time');
                var se_Elm2 = sel_menu2.getElementsByTagName('div');
                var input2 = sel_menu2.getElementsByTagName('input');
                for (var i = 0; i < se_Elm2.length; i++) {
                    se_Elm2[i].index = i;
                    se_Elm2[i].onclick = function () {
                        if (this.className == "check active") {
                            this.className = 'check';
                            input2[this.index].checked = false;
                        } else {
                            this.className = 'check active';
                            input2[this.index].checked = 'true';
                        }
                    }
                }
            }

            /**
             *  检测表单提交
             */
            function checkForm(){
                   var submit = document.getElementsByClassName('radiobox')[2].getElementsByTagName('input');
                   var c_num = 0;
                   for(var i=0;i<submit.length;i++){
                          if (submit[i].checked){
                               c_num++;
                          }
                   }
                   if (c_num==0){
                         layer.msg('坐诊时间必须填写');
                         return false;
                   }
            }
        </script>
    @endsection
@endsection